package com.hanthink.web.controller.pc;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.system.domain.pc.EmResourceCallGroup;
import com.hanthink.system.service.ISysRoleService;
import com.hanthink.system.service.pc.IEmResourceCallGroupService;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.common.utils.StringUtils;

/**
 * 响应用户组Controller
 * 
 * @author hanthink
 * @date 2021-01-25
 */
@RestController
@RequestMapping("/equipment/group")
public class EmResourceCallGroupController extends BaseController
{
    @Autowired
    private IEmResourceCallGroupService emResourceCallGroupService;
    
    @Autowired
    private ISysRoleService roleService;

    /**
     * 查询响应用户组列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmResourceCallGroup emResourceCallGroup)
    {
        startPage();
        List<EmResourceCallGroup> list = emResourceCallGroupService.selectEmResourceCallGroupList(emResourceCallGroup);
        return getDataTable(list);
    }

    /**
     * 导出响应用户组列表
     */
    @Log(title = "响应用户组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmResourceCallGroup emResourceCallGroup)
    {
        List<EmResourceCallGroup> list = emResourceCallGroupService.selectEmResourceCallGroupList(emResourceCallGroup);
        ExcelUtil<EmResourceCallGroup> util = new ExcelUtil<EmResourceCallGroup>(EmResourceCallGroup.class);
        return util.exportExcel(list, "group");
    }

    /**
     * 获取响应用户组详细信息
     */
    @GetMapping(value = { "/", "/{id}" })
    public AjaxResult getInfo(@PathVariable(value = "id" , required = false) Long id)
    {
    	AjaxResult ajax = AjaxResult.success();
    	ajax.put("roles", roleService.selectRoleAll());
    	if (StringUtils.isNotNull(id))
        {
            ajax.put(AjaxResult.DATA_TAG,emResourceCallGroupService.selectEmResourceCallGroupById(id));
//            ajax.put("roleIds", emResourceCallGroupService.selectRoleListById(id));
        }
        return ajax;
//        return AjaxResult.success(emResourceCallGroupService.selectEmResourceCallGroupById(id));
    }

    /**
     * 新增响应用户组
     */
    @PreAuthorize("@ss.hasPermi('equipment:group:add')")
    @Log(title = "响应用户组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmResourceCallGroup emResourceCallGroup)
    {
        return toAjax(emResourceCallGroupService.insertEmResourceCallGroup(emResourceCallGroup));
    }

    /**
     * 修改响应用户组
     */
    @PreAuthorize("@ss.hasPermi('equipment:group:edit')")
    @Log(title = "响应用户组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmResourceCallGroup emResourceCallGroup)
    {
        return toAjax(emResourceCallGroupService.updateEmResourceCallGroup(emResourceCallGroup));
    }

    /**
     * 删除响应用户组
     */
    @PreAuthorize("@ss.hasPermi('equipment:group:remove')")
    @Log(title = "响应用户组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emResourceCallGroupService.deleteEmResourceCallGroupByIds(ids));
    }
}
